package com.econ.powercloud.ems.service.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.econ.powercloud.ems.dal.entity.EmsPriceModelDetail;
import com.econ.powercloud.ems.dal.mapper.EmsPriceModelDetailMapper;
import com.mysql.cj.util.StringUtils;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author : zjf
 * @Description :
 * @Date : 2022/10/18 11:42
 * @Modified by : zjf
 */
@Repository
public class EmsPriceModelDetailDAO extends ServiceImpl<EmsPriceModelDetailMapper, EmsPriceModelDetail> {

    public Page<EmsPriceModelDetail> selectPageByCondition(Integer modelId,String applyTime,Integer priceType,Integer voltageLevel,
                                                    Integer pageNo,Integer pageSize){
        LambdaQueryWrapper<EmsPriceModelDetail> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(modelId != null, EmsPriceModelDetail::getModelId,modelId);
        wrapper.eq(!StringUtils.isNullOrEmpty(applyTime), EmsPriceModelDetail::getApplyTime, applyTime);
        wrapper.eq(priceType != null, EmsPriceModelDetail::getPriceType,priceType);
        wrapper.eq(voltageLevel != null, EmsPriceModelDetail::getVoltageLevel,voltageLevel);
        wrapper.orderByDesc(EmsPriceModelDetail::getApplyTime);
        Page<EmsPriceModelDetail> page = new Page<>(pageNo, pageSize);
        return this.baseMapper.selectPage(page,wrapper);
    }

    public List<EmsPriceModelDetail> selectByModelId(Integer modelId){
        LambdaQueryWrapper<EmsPriceModelDetail> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(EmsPriceModelDetail::getModelId,modelId);
        return this.baseMapper.selectList(wrapper);
    }
}
